import { login } from '@/api/login'
import { setToken, getToken } from '@/utils/storage'
import { Toast } from 'vant'
export default {
  namespaced: true,
  state: {
    token:getToken() || ''
    },
  mutations: {
    login(state, payload) {
      state.token = payload
      setToken(payload)
    }
  },
  actions: {
    async loginSubmit(context, payload) {
      const res = await login(payload)
      // console.log(res);
      if (res.errno !== 0) {
        return Toast.fail(res.errmsg)
      }
      context.commit('login', res.data.token)
      return Toast.success(res.errmsg)
    }
  },
  getters: {}
}
